package com.ict.txmsv2.utils;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

/**
 * @author yoleen
 * @date 2020/12/16 13:30
 */


public class DateUtils {
    //32658000
    public static String convertTimeToStr(long sumTime) {
        sumTime /= 1000;
        String hour = String.valueOf(((int) (sumTime / 3600)));
        String minute = String.valueOf((int) ((sumTime - Integer.parseInt(hour) * 3600) / 60));
        String second = String.valueOf(((int) (sumTime - Integer.parseInt(hour) * 3600 - Integer.parseInt(minute) * 60)));
        if (hour.length() < 2) {
            hour = "0" + hour;
        }
        if (minute.length() < 2) {
            minute = "0" + minute;
        }
        if (second.length() < 2) {
            second = "0" + second;
        }
        return hour + ":" + minute + ":" + second;
    }

    public static String[] getMonth(String date) {
        String begimTime;
        String endTime;
        String[] s = date.split("-");
        if (s[1].equals("12")) {
            begimTime = s[0] + "-11-01";
            int year = Integer.parseInt(s[0]);
            year += 1;
            s[0] = String.valueOf(year);
            endTime = s[0] + "-01-31";
        }else if (s[1].equals("01") || s[1].equals("1")){
            endTime = s[0] + "-02-31";
            int year = Integer.parseInt(s[0]);
            year -= 1;
            s[0] = String.valueOf(year);
            begimTime = s[0] + "-12-01";
        }else {
            int month = Integer.parseInt(s[1]);
            int preMonth = month-1;
            int nextMonth = month+1;
            String pre = preMonth < 10 ? "0"+preMonth : String.valueOf(preMonth);
            String next = nextMonth < 10 ? "0"+nextMonth : String.valueOf(nextMonth);
            begimTime = s[0] + "-"+pre+"-01";
            endTime = s[0] + "-"+next+"-31";
        }
        String[] returnDate = {begimTime, endTime};
        return returnDate;
    }

    public static String[] getYearMonth(){
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String dates = sdf.format(date);
        String[] split = dates.split("-");
        String year = split[0];
        String beginYear = year+"-01"+"-01";
        String endYear = year+"-12"+"-31";
        String month = split[1];
//        String mm = Integer.parseInt(month) < 10 ? "0"+month : month;
        String beginThisMonth = year+"-"+month+"-01";
        String endThisMonth = year+"-"+month+"-31";
        String[] ss = new String[4];
        ss[0] = beginYear; ss[1] = endYear; ss[2] = beginThisMonth; ss[3] = endThisMonth;
        return ss;
    }

    public static Long convertDateToLong(String dtt){
        long time = 0;
        String[] split = dtt.split(":");
        if(split.length == 3){
            time += Integer.parseInt(split[0])*3600*1000;
            time += Integer.parseInt(split[1])*60*1000;
            time += Integer.parseInt(split[2])*1000;
        }
        return time;
    }
}
